package com.qzsoft.zhjd.server.modules.ludong.exp.controller;


import com.qzsoft.zhjd.server.common.utils.MapToBeanUtils;
import com.qzsoft.zhjd.server.common.utils.R;
import com.qzsoft.zhjd.server.modules.ludong.exp.entity.CollectStressMachineEntity;
import com.qzsoft.zhjd.server.modules.ludong.exp.service.CollectStressMachineService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 *
 *功能描述:压力机（水泥抗压抗折机、混凝土抗压抗折一体机）
 * @author jiangyafei
 * @email jiangyf_sd@163.com
 * @date 2020-06-09 11:17:30
 */
@Slf4j
@RestController
@RequestMapping("datacollect/exp/stressmachine")
public class CollectStressMachineController {
    @Autowired
    private CollectStressMachineService collectStressMachineService;


    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestParam Map<String,Object> params){
        log.info("压力机（水泥抗压抗折机、混凝土抗压抗折一体机）==="+params.toString());
        try{
            Map<String,Object> map = MapToBeanUtils.toReplaceKeyLow(params);
            CollectStressMachineEntity collectStressMachineEntity = MapToBeanUtils.mapToObject(map, CollectStressMachineEntity.class);
            if (StringUtils.isNotBlank(collectStressMachineEntity.getId())){
                collectStressMachineService.insertAndRemoveData(collectStressMachineEntity);
                return R.ok();
            }
            return R.error(400,"数据为空或id为空！");
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
            return R.error(400,e.getMessage());
        }

    }


}
